<template>
	<view>
		<template v-if="list.length==0">
			<view class="flexcolumn">
				<view class="placeholderimage" style="margin-top: 200rpx;"></view>
				<view class="xiaohei textcenter ershil">暂无数据</view>
			</view>
		</template>
		<template v-else>
			<view class="mainpadding_top flexbetween ffffff" v-for="item in list" :key="item.id" @click="checkitem(item)">
				<view class="flexleft">
					<template v-if="type==1">
						<view class="margin_right1" v-if="item.ischeck">
							<u-icon name="checkmark-circle-fill" color="#2979ff" size="16"></u-icon>
						</view>
						<view class="weixz margin_right1" v-else></view>
					</template>
					<view class="">
						<view>
							<text class="xiaolv sanshier margin_right3">{{item.name}}</text>
							<text class="xiaohei lable">{{item.datatype==1?'成人':'儿童'}}</text>
						</view>
						<view class="xiaohui margin_top ershil">{{item.idcard}}</view>
					</view>
				</view>
				<view class="flexright">
					<view class="margin_right3" @click.stop="jumpdetail('/pages/mine/tianjiaccr?id=',item.id)">
						<u-icon name="edit-pen" color="#999" size="24"></u-icon>
					</view>
					<view class="" @click.stop="delitem(item)">
						<u-icon name="trash" color="#999" size="24"></u-icon>
					</view>
				</view>
			</view>
		</template>
		
		<view class="mainpadding gudingdb">
			<view class="bigbtn" v-if="type==0" @click="jumpurl('/pages/mine/tianjiaccr')">添加乘车人</view>
			<view class="bigbtn" v-if="type==1" @click="checkperson">确定</view>
		</view>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				list: [],
				type: 0,
				passengers_ids:[],
				tjnum:0
			}
		},
		onLoad(options) {
			if (options.type) {
				this.type = options.type
				this.tjnum = options.tjnum
				this.passengers_ids = options.passengers_ids.split(',')
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			checkitem(item){
				item.ischeck = item.ischeck?false:true
			},
			checkperson() { //选择乘车人
				let arr = []
				this.list.forEach(item => {
					if (item.ischeck) {
						arr.push(item.id)
					}
				})
				if(arr.length>Number(this.tjnum)){
					httpRequest.toast("最多只能选"+this.tjnum+"人")
					return false
				}
				uni.$emit("checkInfo", arr.join())
				uni.navigateBack(1)
			},
			delitem(item) {
				httpRequest.modal('提示', '确认是否删除乘车人', true, (resp) => {
					if (resp) {
						httpRequest.request('/api/user/delPassengers', 'GET', {
							id: item.id
						}).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								this.init()
							}
						}).catch(err => {})
					}
				})

			},
			init() {
				let _this = this
				httpRequest.request('/api/user/passengersIndex', 'GET', {}).then(res => {
					res.data.forEach(item=>{
						this.$set(item,"ischeck",false)
						this.passengers_ids.forEach(ite=>{
							if(item.id==ite){
								item.ischeck = true
							}
						})
					})
					this.list = res.data
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
		}
	}
</script>

<style>
	.lable {
		padding: 0 8rpx;
		border: 1rpx solid #999;
		font-size: 20rpx;
	}
</style>